﻿/*
 * ©2009-2011 XELF
 * http://xelf.info
 */

#if XNA || WINDOWS_PHONE
using Microsoft.Xna.Framework;
#endif

namespace XELF.Framework {
#if XNA || WINDOWS_PHONE
	public static partial class QuaternionHelper {
#else
	public partial struct Quaternion {
#endif
		/// <summary>
		/// 一様乱数分布の回転クォータにオンを作る。
		/// </summary>
		/// <param name="random"></param>
		/// <returns></returns>
		public static Quaternion CreateUniformRandomDistributedRotation(System.Random random) {
			var a = random.NextSingle();
			var b = random.NextSingle() * MathHelper.TwoPi;
			var c = random.NextSingle() * MathHelper.TwoPi;

			var s = MathHelper.Sqrt(a);
			var t = MathHelper.Sqrt(1 - a);

			return new Quaternion(
				t * MathHelper.Sin(b),
				t * MathHelper.Cos(b),
				s * MathHelper.Sin(c),
				s * MathHelper.Cos(c));
		}
	}

}
